var otherserviceCtl = require('../controller/controller.other-service.js');
var sellerCtl = require('../controller/controller.seller.js');

module.exports = {
    getOtherServicetList : function (req, res, next) {

        var params = req.query;
        switch (params.type) {
            default:
                otherserviceCtl.getOtherServiceListbyServiceTime(params, function(err, resultservicetime) {
                    if (err) {
                        res.redirect('/error');
                        return;
                    }

                    otherserviceCtl.getOtherServiceListBySeller(params, function(err, resultseller) {
                        if (err) {
                            res.redirect('/error');
                            return;
                        }
                        next({
                                'servicetimelist': resultservicetime.obj,
                                'sellerlist': resultseller.obj,
                                moment: require("moment")
                            }
                        );
                    })
                })
                break;


        }
    },

    getOtherServiceDetial : function (req, res, next) {
        var params = req.query;
        switch (params.type) {
            default:
                otherserviceCtl.getInfo(params, function(err, result) {
                    if (err) {
                        res.redirect('/error');
                        return;
                    }
                    sellerCtl.getSellerList(params, function(err, resultseller) {
                        if (err) {
                            res.redirect('/error');
                            return;
                        }
                        next({'otherservice': result.obj,
                            'sellerlist':resultseller.obj,
                            moment: require("moment"),
                            uid:req.session.uid
                        });
                    })
                })
                break;


        }
    },
    getSeller : function (req, res, next) {
        var params = req.query;
        switch (params.type) {
            default:
                    sellerCtl.getSellerList(params, function(err, resultseller) {
                        if (err) {
                            res.redirect('/error');
                            return;
                        }
                        next({
                            'sellerlist':resultseller.obj,
                            moment: require("moment")});
                    })
                break;


        }
    },
    deleteOtherService : function (req, res, next) {

        var params = req.body;
        switch (params.type) {
            default:
                otherserviceCtl.deleteOtherService(params, function(err, result) {
                    if (err) {
                        next({
                            'code':404,
                            'message': "删除错误"
                        });
                    }else {
                        next({
                            'code':200,
                            'message': "删除成功"
                        });
                    }
                })
                break;
        }
    },

    createOtherService : function (req, res, next) {

        var params = req.body;
        params["createUid"] = req.session.uid;

        switch (params.type) {
            default:
                otherserviceCtl.create(params, function(err, result) {
                    if (err) {
                        next({
                            'code':404,
                            'message': "保存错误"
                        });
                    }else{
                        next({
                            'code':200,
                            'message': "保存成功"
                        });
                    }
                })
                break;
        }
    },
    updateOtherService : function (req, res, next) {

        var params = req.body;
        params["createUid"] = req.session.uid;

        switch (params.type) {
            default:
                otherserviceCtl.updateOtherService(params, function(err, result) {
                    if (err) {
                        next({
                            'code':404,
                            'message': "更新错误"
                        });
                    }else{
                        next({
                            'code':200,
                            'message': "更新成功"
                        });
                    }
                })
                break;
        }
    }
};
